package com.game.screen.level;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import processing.core.PImage;

import com.game.screen.Collision;
import com.game.screen.Player;
import com.game.util.Coord;
import com.game.util.MP3;
import com.game.util.ProcessingObject;

public class LevelMap extends ProcessingObject{
	private MP3 sound1,sound2;
	 private PImage[][] tiles;
	 private List obstacles;
	 private javazoom.jl.player.Player player;
	public LevelMap(int width, int height) {
		tiles = new PImage[width][height];
	    obstacles = new ArrayList();

  		sound1= new MP3("/data/aaah.mp3");
  		sound2 = new MP3("/data/aqua.mp3");
	}
	 
    public int getWidth() {
        return tiles.length;
    }
    
    public int getHeight() {
        return tiles.length;
    }
    public void addObstacle(Obstacle obstacle) {
        obstacles.add(obstacle);
    }
    
    public void removeObstacle(Obstacle obstacle) {
    	obstacles.remove(obstacle);
    }
    
    public Iterator getObstacles() {
    	return obstacles.iterator();
    }
    
    public void displayMap() {
//    	System.out.println(obstacles.size());
    	Obstacle removeObs = null;
    	
    	for(int i = 0; i < obstacles.size(); i++){
    		Obstacle obstacle = (Obstacle)obstacles.get(i);
//        	System.out.println(obstacle.position.getX() + " : " + obstacle.position.getY());
    		obstacle.display();
    		
    		sound1= new MP3("/data/aaah.mp3");
    		sound2 = new MP3("/data/aqua.mp3");
    		
//    		System.out.println(Player.boy.getX() + ":" + Player.boy.getY());
    		//if(obstacle){
    			if(Collision.isCollision(obstacle, Player.boy)){
    				if (obstacle instanceof Wall) {
        				Player.asleep = false;
        				player = sound1.play();
        				System.out.println("COLLISION!!!");
					} else if(obstacle instanceof Goal){
						Player.asleep = false;
						Player.numBubbles++;
					} else {
						if (((Prize)obstacle).blkColor.equals("cloudbubble.png")) {
							Player.numBubbles+=5;
							player = sound2.play();		
							Player.nextBub = ((Prize)obstacle).blkColor;
							removeObs = obstacle;
						} else if (((Prize)obstacle).blkColor.equals("E2")) {
							Player.numBubbles--;
							player = sound2.play();
							Player.nextBub = "cloudbubble.png";
							removeObs = obstacle;
						} else {
							Player.numBubbles++;
							player = sound2.play();
							Player.nextBub = ((Prize)obstacle).blkColor;
							removeObs = obstacle;
						}
					}
//    				if (obstacle instanceof Wall) {
//						Player.numBubbles++;
//						removeObs = obstacle;
//					} else {
//						Player.numBubbles--;
//						removeObs = obstacle;
//					}
    			}
    		//}	
    	}
    	
    	obstacles.remove(removeObs);
    }
    
}
